package com.claimSettlement.service.impl;

import com.claimSettlement.mapper.ClaimsMapper;
import com.claimSettlement.pojo.*;
import com.claimSettlement.service.ClaimsService;
import com.claimSettlement.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 *菜单Service层接口
 *宁杰
 */
@Service
public class ClaimsServiceImpl implements ClaimsService {
    @Autowired
    ClaimsMapper claimsMapper;
    @Autowired
    RedisTemplate redisTemplate;

    public List<Settlement> getSettlement(Integer userId) {
        List<Settlement> list=null;
//        if(redisTemplate.hasKey("cliamlist")){
//            list=redisTemplate.opsForHash().values("cliamlist");
//            return list;
//        }
        list=claimsMapper.getSettlement(userId);
//        Map<String,String> map=new HashMap<String, String>();
//        for(Settlement settlement:list){
//            map.put(settlement.getSettlementNumber()+"", JsonUtils.objectToJson(settlement));
//        }
//        redisTemplate.opsForHash().putAll("cliamlist",map);
        return list;
    }

    public Integer insertClaims(Map<String,Object> map) {
        claimsMapper.insertAdjustment(map);
        claimsMapper.insertClaims(map);
        return 1;
    }

    public Integer updateClaims(Map<String,Object> map) {
        //claimsMapper.deleteAdjustment(Integer.parseInt(map.get("userId")+""));
        //claimsMapper.insertAdjustment(map);
        claimsMapper.updateClaims(map);
        return 1;
    }

    public Integer deleteClaims(Integer settlement_number) {
        return claimsMapper.deleteClaims(settlement_number);
    }

    public Integer flowState(Integer flowId) {
        return claimsMapper.flowState(flowId);
    }

    public Integer claim_check(Integer settlement_number) {
        return claimsMapper.claim_check(settlement_number);
    }

    public Integer updateClaimCheck(Integer settlement_number,Integer claim_check) {
        return claimsMapper.updateClaimCheck(settlement_number,claim_check);
    }

    public Integer updateFlowState(Integer flowId) {
        return claimsMapper.updateFlowState(flowId);
    }

    public List<Settlement> getSettlementCond(Integer userId,String settlement_number, String warrantyId) {
        return claimsMapper.getSettlementCond(userId,settlement_number,warrantyId);
    }
    public Integer updateCaseState(Integer settlement_number) {
        return claimsMapper.updateCaseState(settlement_number);
    }

    public Integer updateCloseCaseTime(Integer settlement_number) {
        return claimsMapper.updateCloseCaseTime(settlement_number);
    }

    public Settlement getSettlementId(Integer settlement_number) {
        return claimsMapper.getSettlementId(settlement_number);
    }

    public Map<String,Object> getSurveyLossInfo(Integer lossId) {
        Map<String,Object> map=new HashMap<String, Object>();
        map.put("chelosslist",claimsMapper.getCheLossTask(lossId));
        map.put("wulosslist",claimsMapper.getWuLossTask(lossId));
        map.put("renlosslist",claimsMapper.getRenLossTask(lossId));
        return map;
    }

    public List<Justment> getAdjustmentInfo(Integer lossId){
        List<Justment> list=new ArrayList<Justment>();
        list.add(claimsMapper.getAdjustmentInfo(lossId,"lossSum",1,4).get(0));
        if(list.get(0).getPracticalCompensate()<list.get(0).getSubtotal()){
            list.addAll(claimsMapper.getAdjustmentInfo(lossId,"carSubtotal",1,1));
            list.addAll(claimsMapper.getAdjustmentInfo(lossId,"matterSubtotal",2,2));
            list.addAll(claimsMapper.getAdjustmentInfo(lossId,"userSubtotal",3,3));
        }
        return list;
    }
    public List<RiskType> getRiskTypeAll(){
        List<RiskType> list=null;
//        if(redisTemplate.hasKey("risklist")){
//            list=redisTemplate.opsForHash().values("risklist");
//            return list;
//        }
        list=claimsMapper.getRiskTypeAll();
//        Map<String,String> map=new HashMap<String, String>();
//        for(RiskType riskType:list){
//            map.put(riskType.getRiskTypeId()+"", JsonUtils.objectToJson(riskType));
//        }
//        redisTemplate.opsForHash().putAll("risklist",map);
        return list;
    }

    public Integer insertAdjustment(Map<String,Object> map) {
        return claimsMapper.insertAdjustment(map);
    }

    public Integer deleteAdjustment(Integer userId) {
        return claimsMapper.deleteAdjustment(userId);
    }

    public List<Adjustment> getAdjustment(Integer userId) {
        return claimsMapper.getAdjustment(userId);
    }

    public List<LossDetermination> getSettlementTask(Integer userId) {
        return claimsMapper.getSettlementTask(userId);
    }
}
